import { valueType } from './value-type';
export function isEqualObj(obj1: { [key: string]: any }, obj2: { [key: string]: any }) {
    if (obj1 === obj2) return true;
    if (obj1.constructor !== obj2.constructor) {
        return false;
    }
    if (Object.keys(obj1).length !== Object.keys(obj2).length) {
        return false;
    }
    for (let key in obj1) {
        let type1 = Object.prototype.toString.call(obj1[key]);
        let type2 = Object.prototype.toString.call(obj2[key]);
        if (type1 !== type2) {
            return false;
        }
        if (type1 === '[object Object]') {
            if (!isEqualObj(obj1[key], obj2[key])) {
                return false;
            } else {
                continue;
            }
        }
        if (type1 === '[object Array]') {
            if (!isEqualArray(obj1[key], obj2[key])) {
                return false;
            } else {
                continue;
            }
        }
        if (type1 === '[object Date]') {
            // @ts-ignore
            if (obj1[key].getTime() !== obj2[key].getTime()) {
                return false;
            } else {
                continue;
            }
        }
        if (type1 === '[object RegExp]') {
            let reg1 = new RegExp(obj1[key]);
            let reg2 = new RegExp(obj2[key]);
            if (reg1.source !== reg2.source) {
                return false;
            } else {
                continue;
            }
        }
        if (obj2[key] !== obj1[key]) {
            return false;
        }
    }
    return true;
}
export function isEqualArray(arr1: any[], arr2: any[]) {
    if (!Array.isArray(arr1) || !Array.isArray(arr2) || arr1.length !== arr2.length) {
        return false;
    }
    for (let i = 0; i < arr1.length; i++) {
        let type1 = typeof arr1[i];
        let type2 = typeof arr2[i];
        if (type1 !== type2) {
            return false;
        }
        if (type1 === 'object') {
            if (!isEqualObj(arr1[i], arr2[i])) {
                return false;
            } else {
                continue;
            }
        }
        if (arr2[i] !== arr1[i]) {
            return false;
        }
    }
    return true;
}
// export function isEqualMap(val: Map<any>, val1: any) {
//     let obj1 = 
// }
export function isEqual(obj: any, obj2: any) {
    if (obj === null || obj === undefined) {
        return obj === obj2;
    }
    const objType = Object.prototype.toString.call(obj);
    const obj2Type = Object.prototype.toString.call(obj2);
    if (objType !== obj2Type) {
        return false;
    }
    if (objType === '[object Object]') {
        return isEqualObj(obj, obj2);
    }
    if (objType === '[object Array]') {
        return isEqualArray(obj, obj2);
    }
    if (objType === '[object Date]') {
        return obj.getTime() === obj2.getTime();
    }
    if (objType === '[object RegExp]') {
        let reg1 = new RegExp(obj);
        let reg2 = new RegExp(obj2);
        if (reg1.source !== reg2.source) {
            return false;
        } else {
            return true;
        }
    }
    return obj === obj2;
}
export function isGenerateEqual(val: any, val1: any) {
    let valType1 = valueType(val);
    let valType2 = valueType(val1);
    if(valType1 !== valType2 || valType1 === 'Symbol') {
        return false;
    }
    if(valType1 === 'String' || valType1 === 'Number' || valType1 === 'Undefined' || valType1 === 'Null' || valType1 === 'Boolean') {
        if(val !== val1) {
            return false;
        }
    }
    return isEqual(val, val1);
}